package com.zaixiandiancan.xia.util;

import com.sun.jna.Library;
import com.sun.jna.Native;
import com.zaixiandiancan.xia.entity.Order;

import java.util.Map;

public class PrintTscUtil {
    public interface TscLibDll extends Library {
        TscLibDll INSTANCE = (TscLibDll) Native.loadLibrary("TSCLIB", TscLibDll.class);
        int about();
        int openport(String pirnterName);
        int closeport();
        int sendcommand(String printerCommand);
        int setup(String width, String height, String speed, String density, String sensor, String vertical, String
                offset);
        int downloadpcx(String filename, String image_name);
        int barcode(String x, String y, String type, String height, String readable, String rotation, String narrow,
                    String wide, String code);

        int printerfont(String x, String y, String fonttype, String rotation, String xmul, String ymul, String text);
        int clearbuffer();
        int printlabel(String set, String copy);
        int formfeed();
        int nobackfeed();
        int windowsfont(int x, int y, int fontheight, int rotation, int fontstyle, int fontunderline, String
                szFaceName, String content);
    }

    /**
     * 不干胶打印
     * @param
     * @param
     * @param
     * @param
     */
    public static void printBoxCode(Map<Object, Object> order) {
        try {
            //加载驱动
            System.loadLibrary("TSCLIB");
            System.setProperty("jna.encoding", "GBK");
            //Gprinter  GP-1324D
            PrintTscUtil.TscLibDll.INSTANCE.openport("Gprinter  GP-1324D");
            PrintTscUtil.TscLibDll.INSTANCE.sendcommand("SIZE 60 mm,40 mm");//指定标签的宽度
            PrintTscUtil.TscLibDll.INSTANCE.sendcommand("CLS");
            //PrintTscUtil.TscLibDll.INSTANCE.sendcommand("QRCODE 20,30,L,6,A,0,\""+boxCode+"\"");// 打印二维码
            PrintTscUtil.TscLibDll.INSTANCE.printerfont ("170","30", "TSS24.BF2", "0", "1", "1", "订单号:" + order.get("c_time"));
            PrintTscUtil.TscLibDll.INSTANCE.printerfont ("170","65", "TSS24.BF2", "0", "1", "1", "订单时间: " + order.get("o_time"));
            PrintTscUtil.TscLibDll.INSTANCE.printerfont ("170","100", "TSS24.BF2", "0", "1", "1", "订单数量: " + order.get("g_num"));
            PrintTscUtil.TscLibDll.INSTANCE.printerfont("170","135", "TSS24.BF2", "0", "1", "1", "商品名称：" + order.get("g_name"));
            PrintTscUtil.TscLibDll.INSTANCE.printlabel("1", "1");
            PrintTscUtil.TscLibDll.INSTANCE.closeport();
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}
